package pack.coderzheaven;




import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;

public class welcomepage extends Activity{
Button enter;
Boolean isInternetPresent = false;

// Connection detector class
ConnectionDetector cd;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		addListenerOnButton();
		
	}
		
		 
			
			public void addListenerOnButton() {
				final Context context = this;
				enter =(Button) findViewById(R.id.enterButton);
				cd = new ConnectionDetector(getApplicationContext());
				enter.setOnClickListener(new OnClickListener(){
					@Override
					public void onClick(View arg0){
						isInternetPresent = cd.isConnectingToInternet();
						if (isInternetPresent) {
							// Internet Connection is Present
							// make HTTP requests
							showAlertDialog(welcomepage.this, "Internet Connection",
									"You have internet connection", true);
						Intent intent = new Intent(context, AndroidPHPConnectionDemo.class);
						startActivity(intent);
						}else{
							// Internet connection is not present
							// Ask user to connect to Internet
							showAlertDialog(welcomepage.this, "No Internet Connection",
									"You don't have internet connection.", false);
						}
				
				// TODO Auto-generated method stub
				
			}
		});
	}
			
			public void showAlertDialog(Context context, String title, String message, Boolean status) {
				AlertDialog alertDialog = new AlertDialog.Builder(context).create();

				// Setting Dialog Title
				alertDialog.setTitle(title);

				// Setting Dialog Message
				alertDialog.setMessage(message);
				
				// Setting alert dialog icon
				alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

				// Setting OK Button
				alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
					}
				});

				// Showing Alert Message
				alertDialog.show();
			}

	

}
